class Solution(object):
    def isPerfectSquare(self, num):
        """
        :type num: int
        :rtype: bool
        """
        begin, end = 1, num
        while begin<=end:
            mid=(begin+end)//2
            pow = mid*mid
            if pow>num: end=mid-1
            elif pow<num: begin=mid+1
            else: return True
        return False

print(Solution().isPerfectSquare(2))